package com.ogawa.a7517.fragment;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ogawa.a7517.Constant;
import com.ogawa.a7517.R;
import com.ogawa.a7517.bean.DeviceStateBean;
import com.ogawa.a7517.bean.MassageArmchair;

public class GasSkillFragment extends BaseFragment implements View.OnClickListener {
    private TextView tvShoulder, tvArm, tvWhole, tvWaist, tvLeg;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_gas_skill;
    }

    @Override
    public void initView(View view) {
        tvShoulder = view.findViewById(R.id.tv_gas_neck);
        tvArm = view.findViewById(R.id.tv_gas_arm);
        tvWhole = view.findViewById(R.id.tv_gas_whole);
        tvWaist = view.findViewById(R.id.tv_gas_waist);
        tvLeg = view.findViewById(R.id.tv_gas_leg);
        tvShoulder.setOnClickListener(this);
        tvArm.setOnClickListener(this);
        tvWhole.setOnClickListener(this);
        tvWaist.setOnClickListener(this);
        tvLeg.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tv_gas_neck) {
            activity7517.publish(Constant.AIR_CELL_SHOULDER, "2");
        } else if (id == R.id.tv_gas_arm) {
            activity7517.publish(Constant.AIR_CELL_HAND, "2");
        } else if (id == R.id.tv_gas_whole) {
            activity7517.publish(Constant.AIR_CELL_WHOLE_BODY, "2");
        } else if (id == R.id.tv_gas_waist) {
            activity7517.publish(Constant.AIR_CELL_SEAT, "2");
        } else if (id == R.id.tv_gas_leg) {
            activity7517.publish(Constant.AIR_CELL_LEG_FOOT, "2");
        }
    }

    @Override
    public void deviceStateChange() {
        super.deviceStateChange();
        if (!isInit) {
            return;
        }
        DeviceStateBean stateBean = MassageArmchair.getInstance().getDeviceStatusBean();
        if (stateBean != null) {
            DeviceStateBean.FunctionsBean.AirCellShoulderBean airCellShoulder = stateBean.getFunctions().getAirCellShoulder();
            if (airCellShoulder != null) {
                int shoulder = Integer.parseInt(airCellShoulder.getModelValue());
                tvShoulder.setSelected(shoulder == 1);
            }
            DeviceStateBean.FunctionsBean.AirCellHandBean airCellHand = stateBean.getFunctions().getAirCellHand();
            if (airCellHand != null) {
                int hand = Integer.parseInt(airCellHand.getModelValue());
                tvArm.setSelected(hand == 1);
            }
            DeviceStateBean.FunctionsBean.AirCellWholebodyBean airCellWhole = stateBean.getFunctions().getAirCellWholebody();
            if (airCellWhole != null) {
                int whole = Integer.parseInt(airCellWhole.getModelValue());
                tvWhole.setSelected(whole == 1);
            }
            DeviceStateBean.FunctionsBean.AirCellWaistBean airCellWaist = stateBean.getFunctions().getAirCellWaist();
            if (airCellWaist != null) {
                int waist = Integer.parseInt(airCellWaist.getModelValue());
                tvWaist.setSelected(waist == 1);
            }
            DeviceStateBean.FunctionsBean.AirCelllegBean airCellLeg = stateBean.getFunctions().getAirCellleg();
            if (airCellLeg != null) {
                int leg = Integer.parseInt(airCellLeg.getModelValue());
                tvLeg.setSelected(leg == 1);
            }
        }else {
            stateReset();
        }
        int runningStatus = MassageArmchair.getInstance().getRunningStatus();
        if (runningStatus==0){
            stateReset();
        }
    }

    private void stateReset() {
        tvShoulder.setSelected(false);
        tvArm.setSelected(false);
        tvWhole.setSelected(false);
        tvWaist.setSelected(false);
        tvLeg.setSelected(false);
    }
}
